#ifndef _WT_TABLE_H
#define _WT_TABLE_H

/* The table object is a multimap, which is a convenient way
   to access web request parameters. */

/* The table structure */

typedef struct WtTableT {
  Tcl_HashTable items;
} WtTable;

/* Initialize/delete the internal hash table */

Tcl_HashTable *WtGetTableMap(Tcl_Obj *tbl);
void WtInitTableItems(Tcl_Obj *tbl);
void WtDeleteTableItems(Tcl_Obj *tbl);

/* Table methods */

int WtTableSize(Tcl_Obj *tbl);
Tcl_Obj *WtTableGet(Tcl_Obj *tbl, Tcl_Obj *key);
Tcl_Obj *WtTableGetAll(Tcl_Obj *tbl, Tcl_Obj *key);
Tcl_Obj *WtTableGetDefault(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *fallback);
void WtTableSet(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *val);
void WtTableSetAll(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *list);
void WtTableSetDefault(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *val);
void WtTableAdd(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *val);
void WtTableAddList(Tcl_Obj *tbl, Tcl_Obj *key, Tcl_Obj *list);
Tcl_Obj *WtTableKeys(Tcl_Obj *tbl);
Tcl_Obj *WtTableValues(Tcl_Obj *tbl);
Tcl_Obj *WtTableAllValues(Tcl_Obj *tbl);
void WtTableRemove(Tcl_Obj *tbl, Tcl_Obj *key);
void WtTableRemoveList(Tcl_Obj *tbl, Tcl_Obj *list);
void WtUpdateTable(Tcl_Obj *dst, Tcl_Obj *src);
void WtClearTable(Tcl_Obj *tbl);
int WtStringToTable(Tcl_Interp *interp, Tcl_Obj *str, Tcl_Obj *tbl,
                    Tcl_Obj **newTbl, Tcl_ObjType *type);

/* Some convenience functions */

Tcl_Obj *WtGetTableRef(Tcl_Obj *obj, Tcl_ObjType *type, int *created, Tcl_Interp *interp);
int WtTableStrExists(Tcl_Obj *tbl, const char *key);
void WtTableSetStrToStr(Tcl_Obj *tbl, const char *key, const char *val);
void WtTableAddStrToStr(Tcl_Obj *tbl, const char *key, const char *val);
void WtTableSetStrToInt(Tcl_Obj *tbl, const char *key, int val);
void WtTableSetStrToBool(Tcl_Obj *tbl, const char *key, int val);
void WtTableSetStrToObj(Tcl_Obj *tbl, const char *key, Tcl_Obj *val);
char *WtTableGetStrFromStr(Tcl_Obj *tbl, const char *key, char *fallback);
int WtTableGetIntFromStr(Tcl_Obj *tbl, const char *key, int fallback);
int WtTableGetBoolFromStr(Tcl_Obj *tbl, const char *key, int fallback);
Tcl_Obj *WtTableGetObjFromStr(Tcl_Obj *tbl, const char *key, Tcl_Obj *fallback);
void WtTableRemoveStr(Tcl_Obj *tbl, const char *key);

/* Apache table converters */

void WtUpdateTableFromApTable(Tcl_Obj *tbl, table *apTable);
void WtUpdateApTableFromTable(table *apTable, Tcl_Obj *tbl);

/* Constructors */

Tcl_Obj *WtNewTableObj(char *name);
Tcl_Obj *WtNewStringTableObj(char *name);
Tcl_Obj *WtNewTableObjWithType(Tcl_ObjType *type);

/* Get a pointer to the internal table rep */

WtTable *WtToTable(Tcl_Obj *obj);

/* Table object type */

extern Tcl_ObjType WtTableType;
extern Tcl_ObjType WtStringTableType;

/* String table hash key type */

extern Tcl_HashKeyType WtTableCaseKeyType;

#endif /* ! _WT_TABLE_H */
